/*
 *  This file is part of WWWPal.
 *
 *  Copyright (C) 2003  Dr. John Punin, Department of Computer Science
 *  Rensselaer Polytechnic Institute
 *
 *  WWWPal is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  WWWPal is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with Foobar; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

#include "LOGR_sites.h"

WebSiteNodePtr
new_web_site_node(void)
{
  WebSiteNodePtr wsn = (WebSiteNodePtr)calloc(1, sizeof(WebSiteNodeStruct));
  if(!wsn) {
      fprintf(stderr,"Out of Memory new_web_site_node\n");
      abort();
  }
  return wsn;
}

void
delete_web_site_node(WebSiteNodePtr wsn)
{	
    if(!wsn) return;

    if(wsn->dnssite) {
	free(wsn->dnssite); wsn->dnssite = NULL;
    }
    if(wsn->ipsite) {
	free(wsn->ipsite); wsn->ipsite = NULL;
    }
    free(wsn); wsn = NULL;
}

void
LOGR_set_site_dns(WebSiteNodePtr wsn,char *sdns)
{
  if(!wsn) return;
  if(!sdns) return;
  GRStrAllocCopy(wsn->dnssite,sdns);
}

void
LOGR_assign_site_dns(WebSiteNodePtr wsn,char *sdns)
{
  if(!wsn) return;
  wsn->dnssite = sdns;
}

const char *
LOGR_get_site_dns(WebSiteNodePtr wsn)
{
  if(!wsn) return NULL;
  return wsn->dnssite;
}

void
LOGR_set_site_ip(WebSiteNodePtr wsn,char *sip)
{
  if(!wsn) return;
  if(!sip) return;
  GRStrAllocCopy(wsn->ipsite,sip);
}

void
LOGR_assign_site_ip(WebSiteNodePtr wsn,char *sip)
{
  if(!wsn) return;
  wsn->ipsite = sip;
}


const char *
LOGR_get_site_ip(WebSiteNodePtr wsn)
{
  if(!wsn) return NULL;
  return wsn->ipsite;
}

void
LOGR_set_site_naccesses(WebSiteNodePtr wsn,long num)
{
  if(!wsn) return;
  wsn->naccesses = num;
}

void
LOGR_inc_site_naccesses(WebSiteNodePtr wsn)
{
  if(!wsn) return;
  wsn->naccesses++;
}

long
LOGR_get_site_naccesses(WebSiteNodePtr wsn)
{
  if(!wsn) return 0;
  return wsn->naccesses;
}


void
LOGR_set_site_nacc_search(WebSiteNodePtr wsn,long num)
{
  if(!wsn) return;
  wsn->nacc_search = num;
}

void
LOGR_inc_site_nacc_search(WebSiteNodePtr wsn)
{
  if(!wsn) return;
  wsn->nacc_search++;
}

long
LOGR_get_site_nacc_search(WebSiteNodePtr wsn)
{
  if(!wsn) return 0;
  return wsn->nacc_search;
}

void
LOGR_set_site_sizebytes(WebSiteNodePtr wsn,long num)
{
  if(!wsn) return;
  wsn->sbytes = num;
}

void
LOGR_add_site_sizebytes(WebSiteNodePtr wsn,long num)
{
  if(!wsn) return;
  wsn->sbytes += num;
}

long
LOGR_get_site_sizebytes(WebSiteNodePtr wsn)
{
  if(!wsn) return 0;
  return wsn->sbytes;
}

void
LOGR_set_site_sizebytes_search(WebSiteNodePtr wsn,long num)
{
  if(!wsn) return;
  wsn->sbytes_search = num;
}

long
LOGR_get_site_sizebytes_search(WebSiteNodePtr wsn)
{
  if(!wsn) return 0;
  return wsn->sbytes_search;
}


void
LOGR_set_site_type_referer(WebSiteNodePtr wsn,TypeReferer tr)
{
  if(!wsn) return;
  wsn->tr = tr;
}

void
LOGR_set_site_type_referer2(WebSiteNodePtr wsn,TypeReferer tr)
{
  if(!wsn) return;
  wsn->tr |= tr;
}

TypeReferer
LOGR_get_site_type_referer(WebSiteNodePtr wsn)
{
  if(!wsn) return -1;
  return wsn->tr;
}

int
LOGR_is_access_lower(WebSiteNodePtr u, WebSiteNodePtr v)
{
  return (u->naccesses < v->naccesses);
}

int
LOGR_is_access_bigger(WebSiteNodePtr u,WebSiteNodePtr v)
{
  return(u->naccesses > v->naccesses);
}

int
LOGR_is_access_search_lower(WebSiteNodePtr u, WebSiteNodePtr v)
{
  return (u->nacc_search < v->nacc_search);
}

int
LOGR_is_access_search_bigger(WebSiteNodePtr u,WebSiteNodePtr v)
{
  return(u->nacc_search > v->nacc_search);
}

int
LOGR_is_access_stat_lower(WebSiteNodePtr u, WebSiteNodePtr v)
{
  long cu = u->naccesses - u->nacc_search;
  long cv = v->naccesses - v->nacc_search;
  return (cu < cv);
}

int
LOGR_is_access_stat_bigger(WebSiteNodePtr u,WebSiteNodePtr v)
{
  long cu = u->naccesses - u->nacc_search;
  long cv = v->naccesses - v->nacc_search;
  return (cu > cv);
}


